/*
 * @Author: 江舟 jijiangzhou@recycloud.cn
 * @Date: 2024-03-26 20:23:41
 * @LastEditors: 江舟 jijiangzhou@recycloud.cn
 * @LastEditTime: 2024-04-18 11:10:59
 * @FilePath: \vite-project\src\components\org\OrgRoleInfo.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { getRoles } from '@/apis/org';
import { ProTable } from '@ant-design/pro-components';

type TableListItem = {
	id?: string;
};

interface OrgRoleInfoProps {
	parentNode?: any;
}

const OrgRoleInfo: React.FC<OrgRoleInfoProps> = ({ parentNode }) => {
	const columns = [
		{
			title: '角色名称',
			key: 'name',
			dataIndex: 'name',
		},
	];
	return (
		<ProTable<TableListItem>
			params={{
				organizationId: parentNode?.id,
			}}
			search={false}
			columns={columns}
			request={async (params, sorter, filter) => {
				let totalPages = 1;
				return new Promise(async (resolve, reject) => {
					const res = await getRoles({
						pageNumber: params.current,
						pageSize: params.pageSize,
						organizationId: params?.organizationId,
					});
					totalPages = res?.totalRow;
					resolve({
						data: res?.recordDatas || [],
						success: true,
						total: totalPages,
					});
				});
			}}
			rowKey="id"
			pagination={{
				showQuickJumper: true,
			}}
			options={false}
			dateFormatter="string"
		/>
	);
};

export default OrgRoleInfo;
